package com.wondream.myframework.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * 第四种创建线程的方式-使用线程池
 * newCachedThreadPool
 * newFixedThreadPool
 * newSingleThreadExecutor
 */
public class ThreadTest7 {
    public static void main(String[] args) throws Exception {
        int a = 1;
        int b = 1;
//        ExecutorService threadPool = Executors.newFixedThreadPool(5);
//        ExecutorService threadPool = Executors.newCachedThreadPool();
        ExecutorService threadPool = Executors.newSingleThreadExecutor();
        Future<Integer> submit = threadPool.submit(
                ()->a+b
        );
        System.out.println(submit.get());
        threadPool.shutdown();
    }

}
